package com.hualan.sfzy.service.subscribeConsult.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.entity.subscribeConsult.SubscribeConsult;
import com.hualan.sfzy.mapper.subscribeConsult.SubscribeConsultMapper;
import com.hualan.sfzy.service.subscribeConsult.SubscribeConsultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("SubscribeConsultService")
public class SubscribeConsultServiceImpl implements SubscribeConsultService {

    @Autowired
    private SubscribeConsultMapper subscribeConsultMapper;

    @Override
    public int add(SubscribeConsult subscribeConsult) {

        return subscribeConsultMapper.insert(subscribeConsult);
    }

    @Override
    public int remove(Integer id) {
        return subscribeConsultMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return subscribeConsultMapper.deleteBatch(ids);
    }

    @Override
    public int edit(SubscribeConsult subscribeConsult) {
        return subscribeConsultMapper.update(subscribeConsult);
    }

    @Override
    public SubscribeConsult findById(Integer id) {
        return subscribeConsultMapper.selectById(id);
    }

    @Override
    public Map<String, Object> findByPage(Integer pageNum, Integer pageSize, SubscribeConsult subscribeConsult) {
        PageHelper.startPage(pageNum,pageSize);
        List<SubscribeConsult> list = subscribeConsultMapper.select(subscribeConsult);
        PageInfo<SubscribeConsult> pageInfo = new PageInfo<>(list);
        Map<String, Object> map = new HashMap<>();
        // map存储当前页数据、总页数、总记录数
        map.put(CommonConstant.PAGE_LIST, list);
        map.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
        map.put(CommonConstant.TOTAL, pageInfo.getTotal());
        return map;
    }

    @Override
    public List<SubscribeConsult> find() {
        return subscribeConsultMapper.select(null);
    }
}
